package com.adinnet.api.appInform.service.impl;

import com.adinnet.api.appInform.model.AppInform;
import com.adinnet.api.appInform.mapper.AppInformMapper;
import com.adinnet.api.appInform.model.AppInformReq;
import com.adinnet.api.appInform.model.AppInformResp;
import com.adinnet.api.appInform.model.form.AppInformForm;
import com.adinnet.api.appInform.service.AppInformService;
import com.adinnet.core.PageResp;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * app站内、极光通知 服务实现类
 * </p>
 *
 * @author liukp
 * @since 2020-09-03
 */
@Service
public class AppInformServiceImpl extends ServiceImpl<AppInformMapper, AppInform> implements AppInformService {

    /**
     * @description 标记消息已读
     * @author lkp
     * @param
     * @param: idList
     * @createTime 2020/12/11 10:59
     */
    @Override
    public Integer updateRead(List<AppInform> idList) {
        return baseMapper.updateStatus(idList);
    }

    /**
     * @description  查询消息列表
     * @author
     * @param
     * @param: req
     * @createTime 2020/12/11 10:30
     */
    @Override
    public PageResp queryList(AppInformForm req) {
        Page<AppInform> informationPage = new Page<>(req.getPage(), req.getLimit());
        QueryWrapper<AppInform> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("child_id",req.getChildId())
                .lt("status",3)
                .orderByDesc("pubdate");
        IPage<AppInform> iPage = baseMapper.selectPage(informationPage, queryWrapper);
        return new PageResp<>(iPage.getRecords(), iPage.getTotal());
    }
}
